package cn.ecnu.service.forum.impl;

import cn.ecnu.mapper.forum.ForumMapper;
import cn.ecnu.pojo.forum.Forum;
import cn.ecnu.service.forum.ForumService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ForumServiceImpl implements ForumService {

    @Resource
    private ForumMapper forumMapper;

    @Override
    public List<Forum> getForumList() {
        return forumMapper.getForumList();
    }

    @Override
    public Forum getForumById(Integer forumId) {
        return forumMapper.getForumById(forumId);
    }

    @Override
    public Forum getForumByName(String universityName) {
        return forumMapper.getForumByName(universityName);
    }


    @Override
    public int insertForum(Forum forum) {
        return forumMapper.insertForum(forum);
    }

    @Override
    public int updateForum(Forum forum) {
        return forumMapper.updateForum(forum);
    }

    @Override
    public Forum updateForumPostCount(Integer forumId, Integer add) {
        Forum forum = forumMapper.getForumById(forumId);
        forum.setPostCount(forum.getPostCount() + add);
        updateForum(forum);
        return forum;
    }

    @Override
    public Forum updateForumHot(Integer forumId, Integer add) {
        Forum forum = forumMapper.getForumById(forumId);
        forum.setHot(forum.getPostCount() + add);
        updateForum(forum);
        return forum;
    }

}
